先扔完整代碼,可通過在線測試,具體遲點再寫
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int m, n;
cin >> m;
vector<int> arr1(m);
for (int i = 0; i < m; i++)
{
cin >> arr1[i];
}
cin >> n;
int total = (m + n + 1) / 2;
int count = 0;
int i = 0;
for (int j = 0; j < n; j++)
{
int temp = 0;
cin >> temp;
while (i < m&&arr1[i] < temp)
{
count++;
if (count == total)
{
cout << arr1[i];
}
i++;
}
count++;
if (count == total)
{
cout << temp;
}
}
while (i < m&&count<total)
{
count++;
if (count == total)
{
cout << arr1[i];
return 0;
}
i++;
}
}
想研究的可以先去看柳神的解答